package org.example.edusmart.controller.Admin;

import org.example.edusmart.request.admin.CourseInfoPojo;
import org.example.edusmart.service.CourseService;
import org.example.edusmart.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class auditCourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 返回未通过审核的课程
     *
     * @return 课程列表
     */
    @PostMapping("/getUnreviewedCourse/")
    @PreAuthorize("hasAuthority('admin_permission')")
    public Result getUnreviewedCourse() {
        List<HashMap<String, Object>> couserList = courseService.getUnreviewedCourse();
        return new Result(couserList, 200, "查询成功");
    }

    /**
     * 审核课程信息
     *
     * @param courseInfoPojo 信息
     * @return 状态码
     */
    @PostMapping("/auditCourseInfo/")
    @PreAuthorize("hasAuthority('admin_permission')")
    @Transactional(rollbackFor = Exception.class)
    public Result auditCourseInfo(@RequestBody CourseInfoPojo courseInfoPojo) {
        Integer judge = courseService.auditCourseInfo(courseInfoPojo);
        if (judge == 1) {
            return new Result(200, "审核成功");
        }
        return new Result(404, "审核失败");
    }

}
